<template>
	<view :class="[config.style]">
		<FullscreenLoading :loading="loading" :config="config"></FullscreenLoading>
		<!--数据列表部分-->
		<view class="list-section uni-clearfix">
			<!-- top="xxx"下拉布局往下偏移,防止被悬浮菜单遮住 -->
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" top="0" :down="downOption" @down="downCallback" @up="upCallback">
				<!-- 数据列表 -->
				<view class="list">
					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="header">
							<view class="info">
								<view class="title text-ellipsis-2">
									<text class="status no-start" v-if="item.status == 0">待处理</text>
									<text class="status start" v-if="item.status == 1">已完成</text>
									<text class="title-text">{{item.task.title}}</text>
								</view>
							</view>
							<view class="cover">
								<image mode="widthFix" :src="item.task.cover_200" @error="imageError" class="image"></image>
							</view>
						</view>
						<view class="body">
							
							<view class="task-awards" v-if="item.awards.type!='none'">
								
								<view class="cont">
									
									<view class="awards" v-if="item.awards.type == 'score'">
										<view class="title">积分奖励</view>
										<view class="icon">
											<text class="iconfont">&#xe6b4;</text>
										</view>
										<view class="val">
											<text class="dw">积分：</text>
											<text>{{item.awards.score}}</text>
										</view>
									</view>
									
									<view class="awards" v-if="item.awards.type == 'price'">
										<view class="title">现金奖励</view>
										<view class="icon">
											<text class="iconfont">&#xe6b3;</text>
										</view>
										<view class="val">
											<text class="dw">￥</text>
											<text>{{item.awards.price}}</text>
											
										</view>
									</view>
								</view>
								
							</view>
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	//全屏加载中
	import FullscreenLoading from '@/components/muu-fullscreen-loading/muu-fullscreen-loading.vue'
	
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			FullscreenLoading,
		},
		data() {
			return {
				loading: true, //加载中
				urlParams: {}, //url传递过来的参数
				page: 1, //当前页码
				list: [], //列表数据
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption:{
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				}
			}
		},
		async onLoad(option) {
			//获取url参数
			this.urlParams = option
			await this.$nextTick(() => {
				this.loading = false
			})
		},
		created() {
			
		},
		computed: {
			...mapState(['config'])
		},
		methods: {
			//上拉加载的回调
			upCallback: function() {
				let that = this
				//console.log(keyword)
				let data = this.urlParams
					data.action = 'awards_lists'
					data.page = this.page
				//获取数据
				let url = ''
					//#ifdef MP-WEIXIN
					data.m = 'muu_classroom'
					url = 'entry/wxapp/clockin'
					//#endif
					//#ifdef H5
					data.m = 'muu_classroom_plugin_clockin'
					url = 'entry/site/clockin'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							let list = res.data.data.data
							that.list = that.list.concat(list);
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							console.log(that.list)
							that.mescroll.endSuccess(list.length);
							that.page = that.page + 1
						}
					}
				})
			},
			//下拉刷新
			downCallback: function() {
				let that = this
				this.page = 1
				let data = this.urlParams
					data.action = 'awards_lists'
					data.page = this.page
				//获取数据
				let url = ''
					//#ifdef MP-WEIXIN
					data.m = 'muu_classroom'
					url = 'entry/wxapp/clockin'
					//#endif
					//#ifdef H5
					data.m = 'muu_classroom_plugin_clockin'
					url = 'entry/site/clockin'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							that.list = []
							that.list = res.data.data.data
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(that.list.length);
							that.page = 2
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #f8f8f8;
		min-height: 100%;
		height: auto;
	}
	
	.list {
		/*小图*/
		padding: 0 20rpx;
		.item {
			box-sizing:border-box;
			background-color: #fff;
			margin: 30rpx 0;
			border-radius: 20rpx;
			box-shadow: 0 0 10rpx rgba(0,0,0,.05);
			overflow: hidden;
			padding: 30rpx 10rpx;
			.header {
				display: flex;
				.cover {
					position: relative;
					width: 120rpx;
					overflow: hidden;
					.image {
						border-radius: 10rpx;
						width: 100%;
						height: auto;
						display: block;
					}
				}
				.info {
					flex: 1;
					padding: 10rpx;
					.title {
						font-size: 28rpx;
						color: #000;
						font-weight: 600;
						line-height: 36rpx;
						.status {
							display: inline-block;
							width: 90rpx;
							height: 36rpx;
							text-align: center;
							line-height: 36rpx;
							font-size: 24rpx;
							border-radius: 16rpx 16rpx 0 16rpx;
							color: #fff;
							margin-right: 10rpx;
							padding: 4rpx 10rpx;
						}
						.no-start {
							color: #666;
							background-color: #f8f8f8;
						}
						.start {
							color: #fff;
							background-color: #ff6600;
						}
					}
				}
			}
			
			.body {
				margin: 20rpx 10rpx;
				background-color: #f8f8f8;
				border-radius: 10rpx;
				padding: 10rpx;
				.task-awards {
					line-height: 48rpx;
					
					.cont {
						font-size: 26rpx;
						font-weight: 600;
						color: #000;
						text-align: center;
						.title {
							font-size: 34rpx;
							color: #666;
							text-align: center;
							line-height: 68rpx;
							margin-bottom: 30rpx;
						}
						.icon {
							.iconfont {
								font-size: 64rpx;
								color: #ff3300;
							}
						}
						.val {
							.awards {
								.dw {
									margin-right: 20rpx;
								}
								
							}
						}
						
					}
				}
			}
		}
	}
	
	.Blue {
		.price {
			color: $Blue;
		}
	}
	.Green {
		.price {
			color: $Green;
		}
	}
	.LightRed {
		.price {
			color: $LightRed;
		}
	}
	.Orange {
		.price {
			color: $Orange;
		}
	}
	.LightPink {
		.price {
			color: $LightPink;
		}
	}
	.Magenta {
		.price {
			color: $Magenta;
		}
	}
</style>

